package Java7_Concurrency_Cookbook.thread_synchronized_base.read_write_lock;

/**
 *
 * @author lixiangke
 */
public class Writer implements Runnable {

    private PricesInfo pricesInfo;

    public Writer(PricesInfo pricesInfo) {
        this.pricesInfo = pricesInfo;
    }

    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            // System.out.println("Writer : Attempt to modify the prices");
            int price1 = (int)(Math.random() * 10) + 20;
            int price2 = (int)(Math.random() * 10) + 30;
            pricesInfo.setPrices(price1, price2);
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
